<script>
import baseMiXin from "@/views/robotOffice/task/mixin/baseMiXin";

export default {
  name: "competitorProduct",
  mixins: [baseMiXin],
  data() {
    let _vm = this;
    return {
      from: {
        account: "",
        password: "",
        dataCycle: "7天",
        category: ""
      },
      options: {
        dataCycle: ["7天", "30天"]
      },
      rules: {
        account: [
          { required: true, message: "请填写账号" }
        ],
        password: [
          { required: true, message: "请填写密码" }
        ],
        category: [
          { required: true, message: "请填写品类" }
        ],
        dataCycle: [
          { required: true, message: "未选择数据周期" },
          {
            validator: (_rule, value, callback) => {
              if (!_vm.options.dataCycle.includes(value)) {
                callback(new Error(`不支持此数据周期 : ${value}`))
              }
              callback()
            },
            trigger: 'blur',
          }
        ]
      }
    };
  },
  methods: {
    checkParam() {
      let r;
      this.$refs.from1.validate(v => {
        r = v
        return r
      })
      if(!r){
        this.$message.error("任务: [生意参谋-将竞品载入系统] 参数提交失败")
      }
      return r;
    },
    initParams({ account = "", password = "", dataCycle = "7天", category = "" }) {
      this.from.account = account;
      this.from.password = password;
      this.from.dataCycle = dataCycle;
      this.from.category = category;
    },
    getParam() {
      return {
        ...this.from
      };
    }
  }
};
</script>

<template>
  <div style="margin: 10px">
    <el-form :model="from" :rules="rules" ref="from1" label-position="left" label-suffix=" : " :inline="true"
             size="small">
      <el-form-item label="淘系账号" prop="account">
        <el-input v-model="from.account" placeholder="输入账号" style="width: 290px" clearable></el-input>
      </el-form-item>
      <el-form-item label="淘系密码" prop="password" style="margin-left: 30px">
        <el-input v-model="from.password" placeholder="输入密码" style="width: 290px" clearable
                  show-password></el-input>
      </el-form-item>
      <el-form-item label="品类" prop="category">
        <el-input v-model="from.category" placeholder="请输入品类"></el-input>
      </el-form-item>
      <el-form-item label="数据周期" prop="dataCycle" style="margin-left: 100px;">
        <el-tooltip effect="dark" content="当账号不支持获取30天数据时自动获取近7天的数据" placement="top">
          <el-radio-group v-model="from.dataCycle" size="medium">
            <el-radio-button v-for="item in options.dataCycle" :label="item" :key="item">{{ item }}</el-radio-button>
          </el-radio-group>
        </el-tooltip>

      </el-form-item>
    </el-form>
  </div>
</template>

<style scoped>

</style>